The present invention generally relates to threads of computer program execution, and more particularly to managing a pool of threads for executing queued items of work.
A thread is commonly viewed as a light-weight flow of control within a process, wherein a process is a heavy-weight flow of control. A process is heavy-weight in that the operating system allocates a dedicated memory domain for program code and data used by the process, whereas a thread is lightweight in that a thread exists within the memory domain of a process. Some processes are multithreaded such that multiple threads can execute concurrently within a process.
Threads are generally created with support from an operating system and are commonly executed by coupling the thread with a specific operation. That is, a thread is created for the purpose of performing a specific operation. After the operation is complete, the thread may be destroyed or reused in performing the same operation with perhaps different input data.
Creating and initiating new threads can be expensive in terms of consuming operating system resources. Each time a new thread is required, control must be passed to the operating system in order to create the thread, and establish and create any structures required to manage the thread. Thus, some applications create multiple threads for performing the same operation within a process. However, the threads are dedicated to the specific operations for which they were created, which may be inefficient for resource utilization. For example, a first set of threads may be created and dedicated to a first function of a system, and a second set of threads may be created and dedicated to a second function of the system. If demand for the first function is low, wherein only a few of the first set of threads are called upon, and demand for the second function is high, wherein there exists more demand for the second function than there are available threads, then the system""s performance may be constrained by the limited number of threads available for performing the second function. In other words, demands for work performed by the second function may be delayed because of the limited number of threads associated with the second function.
The foregoing scenario illustrates a situation where performance may be degraded even though there may be processing capacity available to meet the demand. Specifically, threads associated with the first function are idle while threads associated with the second function are fully utilized.
A method and system that addresses the aforementioned problems, as well as other related problems, is therefore desirable.
A system and method for managing a pool of threads for executing thread operations. A work queue is provided to support controlled allocation of thread resources for execution of a variety of thread operations. A thread pool is instantiated which includes a plurality of threads, and a work queue having program controllable states is instantiated. Thread operations are queued to the work queue when the work queue is in a running or suspended state, and when the work queue is in a stopped state requests to queue thread operations are denied. In another embodiment, temporary threads can be introduced to the thread pool, for example, to meet a temporary need for additional thread resources.
In accordance with one embodiment of the invention, there is provided a computer program product that is configured to be operable to managing a pool of threads for executing thread operations.
The above summary of the present invention is not intended to describe each disclosed embodiment of the present invention. The figures and detailed description that follow provide additional example embodiments and aspects of the present invention.